<script setup lang='ts'>
  import { onMounted, reactive } from 'vue';
  import { equipApi } from '@/api/controller';
  import { Toastloading } from '@/utils/public';
  import { getPlayEndTime, getDateArray, getHMMSS } from '@/utils'
  import Pagination from "@/components/Pagination/index.vue";
  import serachUserid from '@/components/serachUserid/index.vue';
  const action = reactive({
    dialogFormVisible:false,
    logsList:[] as Array<any>,
    gameList:[] as Array<any>,
    list:[] as any[],
    total:0,
    dateArr:getDateArray('time') as Array<number>
  })
  const listQuery = reactive({
    game_id:'',
    page:1,
    limit:20,
    user_id:''
  })
  const resetQuery = ()=>{
    Object.assign(listQuery,{
      game_id:'',
      page:1,
      limit:20,
      user_id:''
    })
    getList()
  }
  const openlogs = (row:any={})=>{
    const { logs=[] } = row
    action.logsList = logs
    action.dialogFormVisible = true
  }
  const getGameIdList = async()=>{
    const res = await equipApi.gameSwitch()
    const { data=[] } = res || {}
    action.gameList = data
  }
  const handleSerach = ()=>{
    listQuery.page = 1
    getList()
  }
  const getList = async()=> {
    const loading = Toastloading()
    const { playTime:date_st = '', endTime:date_ed=''} = getPlayEndTime(action.dateArr)
    const res = await equipApi.userDrawList({
      ...listQuery,
      date_st,
      date_ed
    })
    loading.close()
    const { data=[],total=0 } = res.data || {}
    action.total = total
    action.list = data
  }
  onMounted(()=>{
    getGameIdList()
    getList()
  })
</script>

<template>
  <div class="xm-content">
    <div class="xm-headTab">
      <div class="labelBox">
        <div class="labelItem">
          <div class="label">游戏ID：</div>
          <el-select v-model="listQuery.game_id" clearable placeholder="请选择游戏ID">
            <el-option v-for="item in action.gameList" :label="item.game_name" :value="item.game_id" />
          </el-select>
        </div>
        <div class="labelItem">
          <div class="label">用户UUID：</div>
          <serachUserid v-model:user_id="listQuery.user_id" />
        </div>
        <div class="labelItem">
          <div class="label">时间：</div>
          <el-date-picker
            v-model="action.dateArr"
            type="datetimerange"
            format="YYYY-MM-DD HH:mm:ss "
            value-format="x"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
          />
        </div>
        <div class="labelItem">
          <el-button type="primary" @click="handleSerach">查询</el-button>
          <el-button type="primary" @click="resetQuery">重置</el-button>
        </div>
      </div>
    </div>
    <el-table
      class="xm-TableCenter"
      :data="action.list"
      border>
      <el-table-column min-width="120" prop="order_id" label="订单ID" />
      <el-table-column min-width="120" prop="game_id" label="游戏ID" />
      <el-table-column min-width="120" prop="game_name" label="游戏名称" />
      <el-table-column min-width="120" prop="user_id" label="用户ID" />
      <el-table-column min-width="120" prop="uuid" label="用户UUID" />
      <el-table-column min-width="120" prop="nickname" label="用户昵称" />
      <el-table-column min-width="120" prop="drawNum" label="总挑战次数" />
      <el-table-column min-width="120" prop="reward_jd_num" label="奖励价值金豆数" />
      <el-table-column min-width="180" prop="created_at" label="时间">
        <template #default="scoped">{{ getHMMSS(scoped.row.created_at * 1000) }}</template>
      </el-table-column>
      <el-table-column min-width="180" fixed="right" prop="logs" label="参与记录">
        <template #default="scoped">
          <el-button type="primary" @click="openlogs(scoped.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <Pagination v-show="action.total > 0" :total="action.total" v-model:page="listQuery.page"
      v-model:limit="listQuery.limit" @pagination="getList" />
    <el-dialog
    top="5vh"
    class="xm-dialog"
    v-model="action.dialogFormVisible"
    width="70%"
    title="产出信息">
      <el-table
        class="xm-main xm-TableCenter"
        :data="action.logsList"
        border>
        <el-table-column width="120" prop="i" label="当前挑战序号" />
        <el-table-column min-width="120" prop="equip_id" label="装备id" />
        <el-table-column min-width="140" prop="equip_name" label="装备名称" />
        <el-table-column min-width="140" prop="pool_one_id" label="一级礼物池id" />
        <el-table-column min-width="140" prop="pool_one_name" label="一级礼物池名称" />
        <el-table-column min-width="140" prop="pool_two_id" label="二级礼物池id" />
        <el-table-column min-width="140" prop="reward_jd_num" label="奖励价值金豆数" />
        <el-table-column min-width="140" prop="if_white" label="是否是白名单礼物池">
          <template #default="scoped">{{ scoped.row.if_white?'是':'否' }}</template>
        </el-table-column>
        <el-table-column min-width="140" prop="rate_type" label="一级礼物池概率类型">
          <template #default="scoped">{{ ['无','基础概率','低回概率','高回概率','新人保护概率','每日保护概率1','每日保护概率2'][scoped.row.rate_type] || scoped.row.rate_type }}</template>
        </el-table-column>

      </el-table>
    </el-dialog>
  </div>
</template>
